#include <stdio.h>

int Count_Digit ( const int N, const int D );

int main()
{
    int N, D;
	
    scanf("%d %d", &N, &D);
    printf("%d\n", Count_Digit(N, D));
    return 0;
}
int Count_Digit ( const int N, const int D )
{
	if(N==0&&D==0){
		return 1;
	}
	int num[12],idx=0;
	int count=0;
	int Nbak=((N>0)?N:(-N));
	while(Nbak!=0){
		num[idx]=Nbak%10;
		Nbak/=10;
		if(num[idx]==D){
			count++;
		}
		idx++;
	} 
	return count;
}
